import Vue from 'vue';
import VueRouter from 'vue-router';
// import Home from '../views/Home.vue';
import Login from '../views/Login.vue';

Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    // 注意是转发的路径
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  // 注册路由
  {
    path: '/home',
    name: 'Home',
    redirect: '/welcome',
    // 这里是一个懒加载：使用到的时候才会加载
    component: () =>
      import('../views/Home.vue'),
    // 二级路由，因为他是二级菜单，所以这是需要写在二级路由的（这样就可以将内容显示在main里面）
    children: [
      {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/About.vue')
      },
      {
        path: '/welcome',
        name: 'Welcome',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/Welcome.vue')
      },
      {
        path: '/pms/product',
        name: 'Product',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/pms/Product.vue')
      },
      {
        path: '/pms/addProduct',
        name: 'AddProduct',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/pms/addProduct.vue')
      },
      {
        path: '/pms/productCate',
        name: 'productCate',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/pms/productCate.vue')
      },
      {
        path: '/pms/productAttr',
        name: 'productAttr',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/pms/productAttr.vue')
      },
      {
        path: '/pms/brand',
        name: 'brand',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/pms/brand.vue')
      },
      {
        path: '/oms/order',
        name: 'order',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        // 这里是一个懒加载：使用到的时候才会加载
        component: () =>
          import(/* webpackChunkName: "about" */ '../views/oms/order.vue')
      }
    ]
  }
];

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new VueRouter({
  routes
});

export default router;
